<!--结清-->
<template>
  <div class="app-container">
    <div class="filter-container">
      <el-tabs v-model="activeName" type="border-card" tab-click="handleClick">
        <el-tab-pane v-for="item in tabMapOptions" :key="item.key" :label="item.label" :name="item.key">
          <div class="car-label">关键字:</div>
          <el-input v-model="listQuery.title" placeholder="Title" style="width: 130px;" class="filter-item" />
          <el-button v-waves style="margin-left: 10px" class="filter-item" type="primary" icon="el-icon-search">
            搜索
          </el-button>
          <el-button v-waves class="filter-item right-btn" type="primary" icon="el-icon-download" @click="handleDownload">
            导出
          </el-button>
          <el-button v-waves class="filter-item right-btn" type="primary" icon="el-icon-download" @click="noNeedInstallGps">
            免装
          </el-button>
          <el-button v-waves class="filter-item right-btn" type="primary" icon="el-icon-download" @click="installGps">
            安装
          </el-button>
          <ve-table
            style="width:100%"
            :columns="activeName==='notInstalled'?columns:notColumn"
            :table-data="tableData"
            :border-x="true"
            row-key-field-name="id"
            :border-y="true"
            :row-style-option="rowStyleOption"
            :checkbox-option="checkboxOptipon"
          />
          <div class="table-pagination">
            <ve-pagination
              :total="totalCount"
              :page-index="pageIndex"
              :page-size="pageSize"
              @on-page-number-change="pageNumberChange"
              @on-page-size-change="pageSizeChange"
            />
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
    <el-dialog
      class="lnk-dialog"
      :close-on-click-modal="false"
      :title="dialogTitle"
      top="10vh"
      width="80%"
      :visible.sync="newDialog"
      :append-to-body="true"
    >
      <GpsDetail :gpsOrderId="selectedRow.gpsOrderId" @canceldialog="canceldialog" :installGps="true"></GpsDetail>
    </el-dialog>
  </div>
</template>

<style scoped lang="scss">
  .table-pagination {
    margin-top: 20px;
    text-align: right;
  }
  .right-btn{
    float: right;
  }

</style>

<script>
import GpsDetail from "./gps-detail"
export default {
  components: {GpsDetail},
  data() {
    return {
      newDialog:false,
      // page index
      pageIndex: 1,
      dataTable: [],
      totalCount: '',
      // page size
      pageSize: 10,
      listQuery: {},
      rowStyleOption: { // 表格样式
        stripe: true, // 斑马纹
        hoverHighlight: true, // hover高亮
        clickHighlight: true // 点击行高亮
      },
      activeName: 'notInstalled',
      tabMapOptions: [
        {
          label: '未安装',
          key: 'notInstalled'
        },
        {
          label: '免安装',
          key: 'installed'
        }
      ],
      selectedRow:{},
      checkboxOptipon: {
        // 行选择改变事件
        selectedRowChange: ({ row, isSelected, selectedRowKeys }) => {
          console.log(row, isSelected, selectedRowKeys)
          if (isSelected){
            this.selectedRow = row;
          }
        },
        // 全选改变事件
        selectedAllChange: ({ isSelected, selectedRowKeys }) => {
          console.log(isSelected, selectedRowKeys)
        }
      },
      columns: [
        {
          field: '',
          key: '1',
          // type=checkbox
          type: 'checkbox',
          title: '',
          width: 50,
          align: 'center'
        },
        {
          field: '',
          key: 'a',
          title: '序号',
          align: 'center',
          renderBodyCell: ({ row, column, rowIndex }, h) => {
            return (this.pageIndex - 1) * this.pageSize + rowIndex + 1
          },
          width: '100px'
        },
        { field: 'orderId', key: 'b', title: '订单编号', align: 'center', width: '150px',
          renderBodyCell: ({ row, column, rowIndex }, h) => {
            console.log(row)
            return (
              <span class={'id-column'} on-click={() => this.gotoDetail(row.id,row.status)}>{row.orderId}</span>)
          } },
        { field: 'status', key: 'c', title: '订单状态', align: 'center', width: '100px' },
        { field: 'customerName', key: 'd', title: '客户姓名', align: 'left', width: '100px' },
        { field: 'carBrand', key: 'e', title: '品牌', width: '100px' },
        { field: 'buyType', key: 'f', title: '车辆类别', width: '' },
        { field: 'loanAmount', key: 'g', title: '贷款金额', width: '100px' },
        { field: 'serviceGroup', key: 'h', title: '部门', width: '100px' },
        { field: 'serviceUser', key: 'i', title: '业务员', width: '100px' }
      ],
      notColumn: [
        {
          field: '',
          key: 'z',
          // type=checkbox
          type: 'checkbox',
          title: '',
          width: 50,
          align: 'center'
        },
        {
          field: '',
          key: 'a',
          title: '序号',
          align: 'center',
          renderBodyCell: ({ row, column, rowIndex }, h) => {
            return (this.pageIndex - 1) * this.pageSize + rowIndex + 1
          }
        },
        { field: 'name', key: 'b', title: '订单编号', align: 'center', width: '100px' },
        { field: 'name', key: 'c', title: 'GPS订单编号', align: 'center', width: '100px' },
        { field: 'date', key: 'd', title: '客户姓名', align: 'left', width: '100px' },
        { field: 'address', key: 'e', title: '部门', width: '' },
        { field: 'address', key: 'f', title: '业务员', width: '' },
        { field: 'address', key: 'g', title: '贷款金额', width: '' },
        { field: 'address', key: 'l', title: '贷款银行', width: '' }
      ],
    }
  },
  computed: {

  },
  created() {
    this.initDatabase()
  },
  methods: {
    // page number change
    pageNumberChange(pageIndex) {
      this.pageIndex = pageIndex
    },

    // page size change
    pageSizeChange(pageSize) {
      this.pageIndex = 1
      this.pageSize = pageSize
    },

    // Simulation table data
    async initDatabase() {
      this.tableData = []
      this.listQuery.appid = this.appId
      const data = await this.$http.post('/flow/orders/list/' + this.pageIndex + '/' + this.pageSize, this.listQuery)
      console.log(data)
      if (data.code === 200) {
        data.data.records.map((item, index) => {
          return item.rowKey = index
        })
        this.tableData = data.data.records
        this.totalCount = data.data.total
        console.log(this.tableData);
      }
    },
    canceldialog(){
      this.newDialog = !this.newDialog;
    },
    /*
     安装Gps按钮函数
    */
    installGps(parentId){
      this.formData = { parentId: parentId }
      this.newDialog = true
      this.dialogTitle = 'GPS安装'
    },

  }
}
</script>
